<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>经营报表</title>
		<link rel="stylesheet" href="dist/css/layui.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/shouy.css" />
	</head>

	<body>
		<div class="wrap">
			<div class="sy_header clearfix">
				<div class="sy_hleft">
					<div class="sy_logobox">
						<div class="sy_logo"><img src="img/logo-ma.png"></div>
						<p id="app_name"></p>
					</div>
					<ul class="sy_nav clearfix">
						<li>
							<a href="index.html">
								<div class="iconfont icon-shouyintai"></div>
								<p>快速收银</p>
							</a>
						</li>
						<li>
							<a href="product_pay.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>商品收银</p>
							</a>
						</li>
						<li>
							<a href="house.html">
								<div class="iconfont icon-shangpinshouyin"></div>
								<p>房台收银</p>
							</a>
						</li>
						<li>
							<a href="xiaof_member.html">
								<div class="iconfont icon-weibiaoti-"></div>
								<p>我的会员</p>
							</a>
						</li>
						<li class="active">
							<a href="jingybb.html">
								<div class="iconfont icon-jingyingbaobiao"></div>
								<p>经营报表</p>
							</a>
						</li>
					</ul>
				</div>
				<div class="sy_shopbox">
					<div class="sy_simg"><img id="toux" src="" style="background-color: #FFFFFF;"></div>
					<div class="sy_sinfo">
						<p class="sy_snam">店名：<span id="sname"></span></p>
						<p>用户：<span id="user">15973240090</span></p>
						<p class="exit" onclick="exit()">退出登陆</p>
					</div>
				</div>
			</div>

			<div class="sy_xconbox clearfix">
				<div class="sy_xftop clearfix">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">订单号</label>
							<div class="layui-input-inline">
								<input type="text" id="sn" placeholder="请输入订单号" name="sn" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">交易时间</label>
							<div class="layui-input-inline" style="width: 120px;">
								<input onclick='WdatePicker()' ignore type="text" placeholder="yyyy-mm-dd" name="date" id="start_time" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">-</div>
							<div class="layui-input-inline" style="width: 120px;">
								<input onclick='WdatePicker()' ignore type="text" placeholder="yyyy-mm-dd" name="date1" id="end_time" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="button" id="search" class="sy_jybtn">搜索</button>
							<button type="button" id="export" class="sy_jybtn green">导出报表</button>
						</div>

					</div>
				</div>
				<div class="sy_spcenter">
					<table class="layui-table">
						<colgroup>
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col width="100">
							<col>
						</colgroup>
						<thead>
							<tr>
								<th>订单号</th>
								<th>用户编号</th>
								<th>消费金额</th>
								<th>鼓励金</th>
								<th>支付方式</th>
								<th>交易类型</th>
								<th>操作员</th>
								<th>交易时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="mem_body">
						</tbody>
					</table>
					<div id="demo2" style="text-align: center;"></div>
				</div>
			</div>
		</div>
			<div class="jjbbp_conbox" style="display: none;">
			<div class="jjbbp_item">
				<div class="jjbbp_bt">交易信息</div>
				<ul class="jjbbp_list clearfix">
					<li>
						<span class="bt">订单号：</span>
						<span id="order_sn" class="nr"></span>
					</li>
					<li>
						<span class="bt">下单时间：</span>
						<span id="add_time" class="nr"></span>
					</li>
					<li>
						<span class="bt">支付时间：</span>
						<span id="pay_time" class="nr"></span>
					</li>
					<li>
						<span class="bt">会员号：</span>
						<span class="nr" id="user_id"></span>
					</li>
					<li>
						<span class="bt">订单金额：</span>
						<span class="nr" id="origin_price"></span>
					</li>
					<li>
						<span class="bt">支付金额：</span>
						<span class="nr" id="pay_price"></span>
					</li>
					<li>
						<span class="bt">支付方式：</span>
						<span class="nr" id="pay_type"></span>
					</li>
					<li>
						<span class="bt">会员鼓励金：</span>
						<span class="nr" id="member_score"></span>
					</li>
					<li>
						<span class="bt">商家鼓励金：</span>
						<span class="nr" id="agent_score"></span>
					</li>
				</ul>
			</div>
			<div class="jjbbp_item2">
				<div class="jjbbp_bt">商品信息</div>
				<div class="jjbbp_table">
					<table class="layui-table">
						<colgroup>
							<col width="39%">
							<col width="15%">
							<col width="10%">
							<col width="12%">
							<col width="12%">
							<col width="12%">
						</colgroup>
						<thead>
							<tr>
								<th>商品</th>
								<th>数量</th>
								<th>小计</th>
							</tr>
						</thead>
						<tbody id="goods_tr">
					
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="dist/jquery-1.11.0.min.js"></script>
		<script src="dist/layui.all.js"></script>
		<script src="dist/json2.js"></script>
		<script src="datepicker/WdatePicker.js"></script>
		<script type="text/javascript" src="js/app.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script>
			if(!document.querySelectorAll) {
				document.querySelectorAll = function(selectors) {
					var style = document.createElement('style'),
						elements = [],
						element;
					document.documentElement.firstChild.appendChild(style);
					document._qsa = [];

					style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
					window.scrollBy(0, 0);
					style.parentNode.removeChild(style);

					while(document._qsa.length) {
						element = document._qsa.shift();
						element.style.removeAttribute('x-qsa');
						elements.push(element);
					}
					document._qsa = null;
					return elements;
				};
			}

			if(!document.querySelector) {
				document.querySelector = function(selectors) {
					var elements = document.querySelectorAll(selectors);
					return(elements.length) ? elements[0] : null;
				};
			}

			// 用于在IE6和IE7浏览器中，支持Element.querySelectorAll方法
			var qsaWorker = (function() {
				var idAllocator = 10000;

				function qsaWorkerShim(element, selector) {
					var needsID = element.id === "";
					if(needsID) {
						++idAllocator;
						element.id = "__qsa" + idAllocator;
					}
					try {
						return document.querySelectorAll("#" + element.id + " " + selector);
					} finally {
						if(needsID) {
							element.id = "";
						}
					}
				}

				function qsaWorkerWrap(element, selector) {
					return element.querySelectorAll(selector);
				}

				// Return the one this browser wants to use
				return document.createElement('div').querySelectorAll ? qsaWorkerWrap : qsaWorkerShim;
			})();
			if(!getValue("agent_id")) {
				location.href = 'login.html';
			}
			$(function() {
				set_info();
				load_dt();
			})
			$("#search").click(function() {
				var sn = $("#sn").val();
				var start_time = $("#start_time").val();
				var end_time = $("#end_time").val();
				load_dt(1, sn, start_time, end_time)

			})
			$("#export").click(function() {
				var begin = $("#start_time").val();
				var end = $("#end_time").val();
				var str = "&begin_time=" + begin + "&end_time=" + end;
				window.location.href = APP.api_url + "sy/export?chain_id=" + getValue("chain_id") + str;
			})

			function load_dt(page, sn, start_time, end_time) {
				layui.use(['laypage', 'layer'], function() {
					var laypage = layui.laypage,
						layer = layui.layer;
					var index = layer.load(1, {
						shade: [0.1, '#fff'] //0.1透明度的白色背景
					});
					$.ajax({
						url: APP.api_url + "Sy/get_reports",
						data: {
							agent_id: getValue("agent_id"),
							chain_id:getValue("chain_id"),
							page: page,
							sn: sn,
							start_time: start_time,
							end_time: end_time,
							app_id	:APP.app_id,
							time:Date.parse( new Date())
						},
						success: function(dt) {
							var mems = dt.list;
							var count = dt.count;
							if(mems) {
								var tr = "";
								for(var m in mems) {
									var log = mems[m];
									var status = "未完成";
									if(log.state == 2) {
										status = "已完成";
									}
									var type = "收银";
									if(log['sy_type'] == 1) {
										type = '快速记账';
									} else if(log['sy_type'] == 2) {
										type = '扫码收银';
									} else if(log['sy_type'] == 3) {
										type = '商品收银';
									}
									var pay_type = "现金";
									if(log['pay_type'] == 2) {
										pay_type = "微信";
									} else if(log['pay_type'] == 3) {
										pay_type = "支付宝";
									}
									var td='<td><a href="#" onclick="print_order(' + log['order_id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a></td>';
									if(log['order_type']==7||log['order_type']==2){
										td='<td><a href="#" onclick="print_order2(' + log['id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a></td>';
									}
									tr += '<tr>' +
										'<td ><a style="color:#d6aa50" href="javascript:show_info('+log['id']+')">' + log['order_sn'] + '</a></td>' +
										'<td>' + log['uid'] + '</td>' +
										'<td>' + log['balance'] + '</td>' +
										'<td>' + log['agent_score'] + '</td>' +
										'<td>' + pay_type + '</td>' +
										'<td>' + type + '</td>' +
										'<td>' + log['clerk_id'] + '</td>' +
										'<td>' + log['add_time'] + '</td>' +
										'<td>' + status + '</td>' +
										 td+
										'</tr>';
								}
								$("#mem_body").html(tr);
								layer.close(index);
								//调用分页
								laypage.render({
									elem: 'demo2',
									count: count,
									limit: 7,
									jump: function(obj, first) {
										//模拟渲染
										var curr = obj.curr;
										if(!first) {
											//layer.msg('第 '+ obj.curr +' 页');
											get_reports(curr);
										}
									}
								});
							}

						}
					})

				});

			}

			function get_reports(page) {
				$.ajax({
					url: APP.api_url + "Sy/get_reports",
					data: {
						agent_id: getValue("agent_id"),
						chain_id:getValue("chain_id"),
						page: page,
						start_time:$("#start_time").val(),
						end_time:$("#end_time").val(),
						app_id	:APP.app_id,
						time:Date.parse( new Date())
					},
					success: function(dt) {
						var mems = dt.list;
						if(mems) {
							var tr = "";
							for(var m in mems) {
								var log = mems[m];
								var status = "未完成";
								if(log.state == 2) {
									status = "已完成";
								}
								var type = "收银";
								if(log['sy_type'] == 1) {
									type = '快速记账';
								} else if(log['sy_type'] == 2) {
									type = '扫码收银';
								} else if(log['sy_type'] == 3) {
									type = '商品收银';
								}
								var pay_type = "现金";
								if(log['pay_type'] == 2) {
									pay_type = "微信";
								} else if(log['pay_type'] == 3) {
									pay_type = "支付宝";
								}
								var td='<td><a href="#" onclick="print_order(' + log['order_id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a></td>';
								if(log['order_type']==7||log['order_type']==2){
									td='<td><a href="#" onclick="print_order2(' + log['id'] + ')" class="layui-btn layui-btn-mini" lay-event="edit">打印</a></td>';
								}
								tr += '<tr>' +
									'<td ><a style="color:#d6aa50" href="javascript:show_info('+log['id']+')">' + log['order_sn'] + '</a></td>' +
									'<td>' + log['uid'] + '</td>' +
									'<td>' + log['balance'] + '</td>' +
									'<td>' + log['score'] + '</td>' +
									'<td>' + pay_type + '</td>' +
									'<td>' + type + '</td>' +
									'<td>' + log['clerk_id'] + '</td>' +
									'<td>' + log['add_time'] + '</td>' +
									'<td>' + status + '</td>' +
									td+
									'</tr>';
							}
							$("#mem_body").html(tr);
						}
					}
				})
			}
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
				//日期
				laydate.render({
					elem: '#start_time'
				});
				laydate.render({
					elem: '#end_time'
				});

			});
			function show_info(id){
				var index = layer.load(1, {
						shade: [0.1, '#fff'] //0.1透明度的白色背景
				});
				$("#goods_tr").html("");
				$.ajax({
					url: APP.api_url + "Sy/get_loginfo",
					data: {
						agent_id: getValue("agent_id"),
						log_id:id,
						app_id: APP.app_id,
						time: Date.parse(new Date())
					},
					success: function(data) {
						var log=data['log'];
						var goods=data['goods'];
						$('#order_sn').text(log['order_sn']);
						$('#add_time').text(log['add_time']);
						$('#pay_time').text(log['pay_time']);
						$('#user_id').text(log['uid']);
						$('#origin_price').text(log['origin_price']);
						$('#pay_price').text(log['balance']);
						if(log['pay_type'] == 2) {
							$('#pay_type').text('微信');
						} else if(log['pay_type'] == 3) {
							$('#pay_type').text('支付宝');
						}else{
							$('#pay_type').text('现金');
						}
						$('#member_score').text(log['member_score']);
						$('#agent_score').text(log['agent_score']);
						if(goods&&goods.length>0){
							var html_tr="";
							for(var i=0;i<goods.length;i++){
								var gd=goods[i];
								html_tr+='<tr>'+
								'<td>'+gd.goods_name+'</td>'+
								'<td>'+gd.num+'</td>'+
								'<td>'+gd.price+'</td>'+
								'</tr>';
							}
							$("#goods_tr").html(html_tr);
						}
						layer.close(index);
						layer.open({
							title: '收款码',
							shadeClose: false,
							shade: 0.8,
							btn: false,
							area: ['750px', '550px'],
							content: $(".jjbbp_conbox").html()
						});
					}
				})
			}
		</script>

	</body>

</html>